///////////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
#ifndef __MATERIAL_H__
#define __MATERIAL_H__
//-----------------------------------------------------------------------------

#include <Config.h>
#include <string>
#include <map>
#include <map>

class	Texture;
class	GPUProgram;
class	Object;

//-----------------------------------------------------------------------------

typedef	struct _struct_shader_var_
{
	u8		func;
	union
	{
		GLfloat	vFloat[4];
		GLint	vInt[4];
	}	value;

	_struct_shader_var_()
	{
		func = 0;
		memset( value.vInt, 0, sizeof( GLint ) * 4 );
	}

	_struct_shader_var_(u8 f, GLfloat v)
	{
		func = f;
		value.vFloat[0] = v;
	}

	_struct_shader_var_(u8 f, GLfloat *v, u8 size)
	{
		func = f;
		memcpy( value.vFloat, v, sizeof( GLfloat ) * size );
	}

	_struct_shader_var_(u8 f, GLint v)
	{
		func = f;
		value.vInt[0] = v;
	}

	_struct_shader_var_(u8 f, GLint *v, u8 size)
	{
		func = f;
		memcpy( value.vInt, v, sizeof( GLint ) * size );
	}

}	_shader_var_;


class Material
{
public:
					Material();
					Material( std::string name );
	virtual			~Material();

	void			SetName( std::string name );
	std::string		GetName();

	void			Activate( Object* obj );
	void			Deactivate();

	f32				m_ambient[4];
	f32				m_diffuse[4];
	f32				m_specular[4];
	f32				m_emissive[4];
	f32				m_shininess;
	std::map<u8,Texture*>	m_textures;
	std::map<u8,GPUProgram*>		m_shaders;
	GPUProgram*		m_activeShader;

	void SetParameter1i(const char* paramName, int value);
	void SetParameter2i(const char* paramName, int* value);
	void SetParameter3i(const char* paramName, int* value);
	void SetParameter4i(const char* paramName, int* value);

	void SetParameter1f(const char* paramName, float value);
	void SetParameter2f(const char* paramName, float* value);
	void SetParameter3f(const char* paramName, float* value);
	void SetParameter4f(const char* paramName, float* value);

protected:
	
	void sendSavedParams();

private:

	/**
	*	Shader vars saves
	*/
	std::map<std::string,_shader_var_> m_shaderVarSaves;

	void			init();

	std::string		m_name;

};

#endif // __MATERIAL_H__
//-----------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
